import { createStore } from 'vuex'
import menu from "./modules/menu"
import role from './modules/role'
import user from './modules/user'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import member from './modules/member'
import banner from './modules/banner'
import seck from './modules/seck'

let a = sessionStorage.getItem("userInfo")
export default createStore({
  state: {
    userInfo: a ? JSON.parse(a) : null
  },
  getters: {
    getUser(state: any) {
      return state.userInfo
    }
  },
  mutations: {
    REQ_USERINFO(state: any, payload: any) {
      if (payload) {
        state.userInfo = payload
        //判断如果payload有值的话进行存储
        sessionStorage.setItem("userInfo", JSON.stringify(payload))
      }
    }
  },
  actions: {
    changeUser(context: any, payload: any) {
      context.commit("REQ_USERINFO", payload)
    }
  },
  modules: {
    menu,
    role,
    user,
    cate,
    specs,
    goods,
    member,
    banner,
    seck
  }
})
